/**
 * Created by 陈奇 on 15-4-25.
 */
var express = require('express');
var router = express.Router();
var db = require('./../routes/conn');//先引入数据库链接

router.get('/', function(req, res) {
    var bookid = req.param('bookid');
    var name = req.param('name');
    var prize = req.param('prize');
    var imgurl = req.param('imgurl');

    db.pool.getConnection(function(err, connection) {
        var  sql = 'insert into bookinfo(bookid,name,prize,imgurl) values(?,?,?,?)';
        var  sql_val = [bookid,name,prize,imgurl];

        connection.query( sql,sql_val, function(err, result) {
            if(err){
                res.render('addBook',{ title: '增加图书' });
                
            }else{
                res.redirect('index');
            }
        });
        connection.release();
    });
});

module.exports = router;